#! /usr/bin/env python
#coding=utf-8

from get_month_quarter import *


#from __future__ import division


#调用get_month_quarter.py中get_db_connection()获取数据库联接
db = get_db_connection()

#meta = MetaData(db)
#db.metadata.reflect()

def set_question_need_discuss_flag_run():
    Q = get_model('question')
    R = get_model('risk')
    today = datetime.date.today()
    twentyone = datetime.timedelta(days=14)
#    print '-------',today - twentyone
    for row in Q.filter(and_(Q.c.submit_date <= (today - twentyone),Q.c.status != 'F',Q.c.need_discuss == False)):
#        print '333333333333',row.id
        Q.table.update(Q.c.id == row.id).execute(need_discuss = True)
    for row in R.filter(and_(R.c.submit_date <= (today - twentyone),R.c.status != 'F',R.c.need_discuss == False)):
#        print '88888888888888',row.id
        R.table.update(R.c.id == row.id).execute(need_discuss = True)
    
    
if __name__ == '__main__':
    try:
        db.begin()
        set_question_need_discuss_flag_run()
        db.commit()
        log.info("finish")
    except Exception, e:
        db.rollback()
        log.exception(e)
        log.error('error')
        raise
    
